<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<!DOCTYPE html>
<html>
<head>
	<link rel="stylesheet" href="${ctx}/css/contractQuery.css"/>
	<link rel="stylesheet" href="${ctx}/css/iconfont.css"/>
	<jsp:include page="../inc_min.jsp"></jsp:include>
<title>订单管理-合同订单</title>
<script type="text/javascript">
	$(function() { 
		//状态背景文字切换
		$(".listArg").click(function(){
			$(".listArg").css({
				"background": "#f1f1f1",
				"color": "black"
			});
			$(this).css({
				"background": "#28aaf0",
				"color": "#FFFFFF"
			});
			//$(".listArg").removeClass("allStatus"); 
			//alert($(this).find("span").attr('id'))
			var conStatus=$(this).find("span").attr('id');
			getajax(conStatus);
		});
		//进入页面时  加载列表项
	//	 progressLoad();
		getajax(-1);
		//点击查询  加载表格项
		$("#query").click(function(){
            pageNum = 1;
            getajax(-1);
		});

		//刷新
		$('.reflesh').click(function(){
			window.location.reload();
		})
		
	}); 
	//封装函数  实现查询订单功能
	//全局变量 总页数
	var pageNum = 1;
	function getajax(conStatus){
		var pageSize = 20;
		var conNo=$("#conNo").val();
		//var conStatus=$("#conStatus").val();
		var toStartAirportCode=$("#startCity").val();
		var toEndAirportCode=$("#arrCity").val();
		//console.log(conNo+"+"+conStatus+"+"+toStartAirportCode+"+"+toEndAirportCode+"+"+toStartDate);
		//发送ajax请求  根据参数返回值
		if(typeof(toStartAirportCode) == 'undefined'){
			toStartAirportCode = "";
		}
		if(typeof(toEndAirportCode) == 'undefined'){
			toEndAirportCode = "";
		}
		$.get("${ctx}/search/contractList?conNo="
				+conNo+"&conStatus="+conStatus
				+"&deptAirportCode="
				+toStartAirportCode+"&arrAirportCode="
				+toEndAirportCode+"&temp="
				+Math.random()+"&page="
				+pageNum+"&rows="
				+pageSize+"&msgTime=${message.startTime}"+"&msgStatus=${message.status}",function(data){
            $('table tbody').empty();
            var str = "";
            for(var i=0;i<data.list.length;i++){
                var obj = data.list[i];
                var tablebutton = "";
                var time=obj.payOverTime;
               	if(time == null || time == undefined){
               		time="";
               	}else{
               		time=time.replace(" ","=");
               	};
                //var moredetail="<span onclick=moreDetail('"+obj.conNo+"','"+obj.conStatus+"','"+time+"')>查看详情》</span>";
                var moredetail='<i class="icon iconfont position" title="详情" onclick=moreDetail("'+obj.conNo+'","'+obj.conStatus+'","'+time+'")>&#xe62d;</i>';
                if(obj.conStatus==2){  //待支付状态时 显示支付押金按钮
                	moredetail="<button class='add_minus' style='width:80px;' onclick=payDeposit('"+obj.conNo+"','"+obj.deposit+"','"+time+"')>支付押金</button>";
                  //待支付状态时  显示倒计时
                    var timeId = "time"+obj.conNo;
					var timeSec = obj.seconds;
					if(timeSec>0){
						 var timer_rt = window.setInterval("GetRTime("+timeSec+",'"+timeId+"')", 1000);
					};
					 timeOut='<span style="color:#ff8800;">'+CommonConverter.toContractStatusStr(obj.conStatus)+'</span><img src="${ctx}/image/delay_out.png" style="vertical-align:middle">'+
					'<br/>剩余保留时间：<span id="'+timeId+'"></span>';
                }else{
                	timeOut=CommonConverter.toContractStatusStr(obj.conStatus);
                };
                str+="<tr height='38px' class='reBorder'>"
                str+="	<td width='246px' align='center'>合同号："+obj.conNo+"</td>"
                str+="	<td width='939px' align='left' colspan='6'>&nbsp;&nbsp;&nbsp;</td>"
                str+="	<td width='117px' align='center' style='color:#fdc473;cursor:pointer;'>"+moredetail+"</td>";
                str+="</tr>"
                str+="<tr height='90px'>"
                str+="	<td width='208px' style='color:#444e50' align='right'>"
                str+=  obj.deptAirport + "("+obj.deptAirportCode+")"
                str+="	</td>"
                str+="	<td width='165px' align='center'>"
                str+="		<img src='${ctx}/image/flightQuery/dancheng.png'>"
                str+="	</td>"
                str+="	<td width='208px' style='color:#444e50'>"
                str+=   obj.arrAirport + "("+obj.arrAirportCode+")"
                str+="	</td>"
                str+="	<td width='88px' align='center' style='color:#444e50'>"+obj.productList.substring(0,obj.productList.length-1)+"</td>"
                str+="	<td width='86px' align='center' style='color:#444e50'>"+obj.seatCount+"</td>"
                str+="	<td width='96px' align='center' style='color:#e2615c'>"+obj.deposit+"</td>"
                str+="	<td width='151px' style='color:#e2615c' align='center'>"
                str+="		<span>"+timeOut+"</span>"
                str+="	</td>"
                str+="	<td width='139px' align='center' style='color:#e2615c'>"
                str+=tablebutton;
                str+="	</td>"
                str+="</tr>"
            }
            $('#tb').append(str);
            //显示分页
            layui.use(['laypage', 'layer'], function(){
                var laypage = layui.laypage;
                laypage({
                    cont: 'pager'
                    ,pages: data.pages //得到总页数 //总页数
                    ,groups: 5 //连续显示分页数
                    ,skin: '#1E9FFF'
                    ,curr : pageNum
                    ,jump: function(obj,first){
                        if(!first){
                            pageNum = obj.curr;
                            getajax(conStatus);
                        }
                    }
                });
            });
		})
		
	};
	
	//更多详情
	function moreDetail(conNo,conStatus,payOverTime){
		window.location.href='${ctx}/np/lookMore?conNo='+conNo+'&conStatus='+conStatus+'&payOverTime='+payOverTime;
	};
	//支付押金
	function payDeposit(conNo,deposit,payOverTime){
		//alert(payOverTime);
		var str={"deposit":deposit,"payOverTime":payOverTime};
		$.ajax({
			type:'post',
			//contentType:'application/json;charset=utf-8',
			url:'${ctx}/nporder/payDeposit/'+conNo,
			dataType:'json',
			data:str,
			success:function(json){//返回json结果
				//alert(json.msg);
				//window.location.href="${ctx}/np/contractQuery?temp="+Math.random();
				if(json.success){
					layer.alert('支付押金成功！支付金额：'+deposit+'元'
				        	,{skin:'layui-layer-lan',title: ['系统提示', 'background-color:#00B2EE; color:#fff;'],closeBtn: 0}
				        	, function(index){
                                getajax(-1);
								layer.close(index);
							});
				}else{
					layer.alert(json.msg);
				}
				
			},
			error:function(msg){
		    	layer.alert("请检查您的网络连接，然后重试！");
		    }
		});
		layer.close(index);
	};

</script>
</head>
<body>
<jsp:include page="../head.jsp"></jsp:include>
<div class="content">
			<ul class="list">
					<li>
						合同号：
						<input type="text" id="conNo"   style="width:150px"/>
					</li>
					<li>出发城市：
						<input type="text" class="textbox" value="" size="15" id="homecity_name" name="homecity_name" style="width:150px" mod="address|notice" mod_address_source="hotel" mod_address_suggest="" mod_address_reference="startCity" mod_notice_tip="中文/拼音" />
						<input id="startCity" name="startCity" type="hidden" value="" />
						</li>
						<li>
							到达城市：
							<input type="text" class="textbox" value="" size="15" id="getcity_name" name="getcity_name" style="width:150px" mod="address|notice" mod_address_source="hotel"  mod_address_reference="arrCity" mod_notice_tip="中文/拼音" />
							<input id="arrCity" name="arrCity" type="hidden" value="" />
						</li>
						<li class="right">
							<input type="button" value="查询" class="mynewBtn" id="query"/>
						</li>
				</ul>
				<ul class="list conditionList">
					<li>状态：</li>
					<li class="listArg allStatus">
						<span id="-1" />全部</span>
					</li>
					<li class="listArg">
                        <span id="1">待审核</span>
					</li>
					<li class="listArg">
						<span id="2">待支付</span>
					</li>
					<li class="listArg">
						<span id="3">押金已收</span>
					</li>
					<li class="listArg">
						<span id="4">合同中止</span>
					</li>
					<li class="listArg">
						<span id="5" >合同完成</span><span id="auditCount"></span></a>
					</li>
					<li class="listArg">
						<span id="6">合同退回</span>
					</li>
					<li class="listArg">
						<span id="7">合同取消</span>
					</li>
				</ul>
			<table class="conTable" >
				<thead>
					<tr height="38px" >
						<td width="234px" align="right">出发</td>
						<td width="90px" align="center">&nbsp;&nbsp;&nbsp;</td>
						<td width="171px" align="left">到达</td>
						<td width="246px" align="center">产品列表</td>
						<td width="135px" align="center">预定人数</td>
						<td width="178px" align="center">押金金额(CNY)</td>
						<td width="103px" align="center">状态</td>
						<td width="143px" align="center">操作</td>
					</tr>
				</thead>
				<tbody id="tb">
				</tbody>
			</table>
			<!-- 分页 -->
            <div id="pager" class="divBox"></div>
</div>

<script type="text/javascript" src="${ctx }/jslib/airport/fixdiv.js"></script>
<script type="text/javascript" src="${ctx }/jslib/airport/address.js"></script>
<jsp:include page="../footer.jsp"></jsp:include>
</body>
</html>